
package org.springblade.modules.app.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiParam;
import org.springblade.common.config.NoRepeatSubmit;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.app.entity.Fankui;
import org.springblade.modules.app.service.IFankuiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 意见反馈 控制器
 *
 * @author BladeX
 * @since 2020-08-18
 */
@RestController
@RequestMapping("blade-app/fankui")
public class FankuiController extends BladeController {

    @Autowired
    private IFankuiService fankuiService;

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<Fankui> detail(Fankui fankui) {
        Fankui detail = fankuiService.getOne(Condition.getQueryWrapper(fankui));
        return R.data(detail);
    }

    /**
     * 分页 意见反馈
     */
    @GetMapping("/list")
    public R<IPage<Fankui>> list(Page page, Fankui params) {
        IPage<Fankui> result = fankuiService.page(page, Wrappers.query(params));
        return R.data(result);
    }

    /**
     * 自定义分页 意见反馈
     */
    @GetMapping("/page")
    public R<IPage<Fankui>> page(Fankui fankui, Query query) {
        IPage<Fankui> pages = fankuiService.selectFankuiPage(Condition.getPage(query), fankui);
        return R.data(pages);
    }

    /**
     * 新增 意见反馈
     */
    @NoRepeatSubmit
    @PostMapping("/save")
    public R save(@RequestBody Fankui fankui) {
        BladeUser user = AuthUtil.getUser();
        fankui.setUserid(user.getUserId());
        fankui.setUsername(user.getUserName());
        fankui.setCtime(new Date());
        return R.status(fankuiService.save(fankui));
    }

    /**
     * 修改 意见反馈
     */
    @PostMapping("/update")
    public R update(@RequestBody Fankui fankui) {
        return R.status(fankuiService.updateById(fankui));
    }

    /**
     * 新增或修改 意见反馈
     */
    @PostMapping("/submit")
    public R submit(@RequestBody Fankui fankui) {
        return R.status(fankuiService.saveOrUpdate(fankui));
    }


    /**
     * 删除 意见反馈
     */
    @PostMapping("/remove")
    public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return R.status(fankuiService.removeByIds(Func.toLongList(ids)));
    }


}
